package com.kafka.sync2;

import java.io.File;
import java.net.URISyntaxException;
import java.security.CodeSource;
import java.util.Objects;

/**
 * @author xq
 * @Description: 类的工具类
 * @date 2020/6/1510:54
 */
public class ClassUtils {

    public static void main(String[] args) {
        System.out.println(getCurrentProgramPath());
    }

    private ClassUtils() {
    }

    public static File getCurrentProgramPath() {
        CodeSource codeSource = ClassUtils.class.getProtectionDomain().getCodeSource();
        File jarFile = null;
        try {
            jarFile = new File(codeSource.getLocation().toURI().getPath());
        } catch (URISyntaxException e) {
            e.printStackTrace ();
        }

        return Objects.requireNonNull (jarFile, "jar file should not be null.").getParentFile ();
    }

}
